#!/usr/bin/python
# -*-coding:UTF-8 -*-

# ========================
# @Time  : 2021/3/9
# @Author: Sunny
# ========================
"""
concurrent.futures模块中对线程池和进程池又进行了进一步的封装，使用更方便
ThreadPoolExecutor,ProcessPoolExecutor

"""
import os
import time
from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor


def work(name,age):
    for i in range(3):
        time.sleep(1)
        print(f'{name}:--{age}------work{i}----------')



# 创建一个线程池，设置最多可以开启5个线程
# ThreadPoolExecutor这个模块里面是实现了上下文管理协议的,可以直接用with启动上下文机制
# 就不需要再关闭线程池了
with ThreadPoolExecutor(max_workers=5) as ts:
    ts.submit(work, 'musen',18)
    ts.submit(work, 'musen', 19)
    ts.submit(work, 'musen', 20)
    ts.submit(work, 'musen', 21)
    ts.submit(work, 'musen', 22)
    ts.submit(work, 'musen', 23)
    ts.submit(work, 'musen', 24)
    ts.submit(work, 'musen', 25)
